//
//  UIModels.swift
//  tverify
//
//  Created by changlei on 2023/8/14.
//

import Flutter
import UIKit
import TXLoginoauthSDK

extension TXLoginUIModel {
    public convenience init(_ arguments: [String: Any], plugin: TverifyPlugin) {
        self.init()
        if let value = arguments["appLanguageType"] as? Int {
            self.appLanguageType = AuthLanguageType.init(rawValue: UInt(value))!
        }
        if let value = arguments["appPrivacy"] as? [[String: Any]] {
            self.appPrivacy = value.map(toNSAttributedString)
        }
        if let value = arguments["appPrivacyDemo"] as? [String: Any] {
            self.appPrivacyDemo = toNSAttributedString(value)
        }
        if let value = arguments["appPrivacyOriginLR"] as? [NSNumber] {
            self.appPrivacyOriginLR = value
        }
        if let value = arguments["authWindow"] as? Bool {
            self.authWindow = value
        }
        if let value = arguments["brandLabelTextSize"] as? [String: Any] {
            self.brandLabelTextSize = toUIFont(value)
        }
        if let value = arguments["checkBoxWH"] as? CGFloat {
            self.checkBoxWH = value
        }
        if let value = arguments["checkTipText"] as? String {
            self.checkTipText = value
        }
        if let value = arguments["checkboxOffsetX"] as? NSNumber {
            self.checkboxOffsetX = value
        }
        if let value = arguments["checkboxOffsetY"] as? NSNumber {
            self.checkboxOffsetY = value
        }
        if let value = arguments["checkboxOffsetY_B"] as? NSNumber {
            self.checkboxOffsetY_B = value
        }
        if let value = arguments["checkedImg"] as? [String: Any] {
            self.checkedImg = toUIImage(value)
        } else if let image = UIImage(innerName: "checkBox_selected@3x.png") {
            self.checkedImg = image
        }
        if let value = arguments["controllerSize"] as? [String: Any] {
            self.controllerSize = toCGSize(value)
        }
        if let value = arguments["cornerRadius"] as? CGFloat {
            self.cornerRadius = value
        }
        if let value = arguments["customBackgroundView"] as? [String: Any] {
            self.customBackgroundView = UICustomView.init(value, plugin: plugin)
        }
        if let value = arguments["customOtherLoginViews"] as? [[String: Any]] {
            self.customOtherLoginViews = value.map { element in
                UICustomView.init(element, plugin: plugin)
            }
        }
        if let value = arguments["customTopLoginView"] as? [String: Any] {
            self.customTopLoginView = UICustomView.init(value, plugin: plugin)
        }
        if let value = arguments["edgeWindow"] as? Bool {
            self.edgeWindow = value
        }
        if let value = arguments["faceOrientation"] as? Bool {
            self.faceOrientation = value
        }
        if let value = arguments["iconImage"] as? [String: Any] {
            self.iconImage = toUIImage(value)
        } else if let image = UIImage(innerName: "logo@3x.png") {
            self.iconImage = image
        }
        if let value = arguments["ifCreateCustomView"] as? Bool {
            self.ifCreateCustomView = value
        }
        if let value = arguments["ignorePrivacyState"] as? Bool {
            self.ignorePrivacyState = value
        }
        if let value = arguments["isShowLoginLoadingView"] as? Bool {
            self.isShowLoginLoadingView = value
        }
        if let value = arguments["logBtnHeight"] as? CGFloat {
            self.logBtnHeight = value
        }
        if let value = arguments["logBtnOffsetY"] as? CGFloat {
            self.logBtnOffsetY = value
        }
        if let value = arguments["logBtnOriginLR"] as? [NSNumber] {
            self.logBtnOriginLR = value
        }
        if let value = arguments["logBtnText"] as? [String: Any] {
            self.logBtnText = toNSAttributedString(value)
        }
        if let value = arguments["loginBtnColors"] as? [[String: Any]] {
            self.loginBtnColors = (value).map(toUIColor)
        }
        if let value = arguments["loginBtnImgs"] as? [[String: Any]] {
            self.loginBtnImgs = value.map { data in
                toUIImage(data)
            }
        } else if
            let image1 = UIImage(innerName: "loginBtn_Nor@3x.png"),
            let image2 = UIImage(innerName: "loginBtn_Dis@3x.png"),
            let image3 = UIImage(innerName: "loginBtn_Dis@3x.png") {
            self.loginBtnImgs = [
                image1,
                image2,
                image3
            ]
        }
        if let value = arguments["loginLoadingView"] as? [String: Any] {
            self.loginLoadingView = UICustomView.init(value, plugin: plugin)
        }
        if let value = arguments["logoFrame"] as? [String: Any] {
            self.logoFrame = toCGRect(value)
        }
        if let value = arguments["logoHidden"] as? Bool {
            self.logoHidden = value
        }
        if let value = arguments["modalPresentationStyle"] as? Int {
            self.modalPresentationStyle = UIModalPresentationStyle(rawValue: value)!
        }
        if let value = arguments["modalTransitionStyle"] as? Int {
            self.modalTransitionStyle = UIModalTransitionStyle(rawValue: value)!
        }
        if let value = arguments["numberOffsetX"] as? NSNumber {
            self.numberOffsetX = value
        }
        if let value = arguments["numberTextAttributes"] as? [String: Any] {
            self.numberTextAttributes = toNSAttributedStringAttributes(value)
        }
        if let value = arguments["presentAnimated"] as? Bool {
            self.presentAnimated = value
        }
        if let value = arguments["presentType"] as? Int {
            self.presentType = RICHPresentationDirection.init(rawValue: UInt(value))!
        }
        if let value = arguments["privacyColor"] as? [String: Any] {
            self.privacyColor = toUIColor(value)
        }
        if let value = arguments["privacyLabelOffsetY"] as? CGFloat {
            self.privacyLabelOffsetY = value
        }
        if let value = arguments["privacyObserve"] as? Bool {
            self.privacyObserve = value
        }
        if let value = arguments["privacyState"] as? Bool {
            self.privacyState = value
        }
        if let value = arguments["privacyUncheckAnimation"] as? Bool {
            self.privacyUncheckAnimation = value
        }
        if let value = arguments["scaleH"] as? CGFloat {
            self.scaleH = value
        }
        if let value = arguments["scaleW"] as? CGFloat {
            self.scaleW = value
        }
        if let value = arguments["sloganHidden"] as? Bool {
            self.sloganHidden = value
        }
        if let value = arguments["sloganLabelOffsetY"] as? CGFloat {
            self.sloganLabelOffsetY = value
        }
        if let value = arguments["sloganTextColor"] as? [String: Any] {
            self.sloganTextColor = toUIColor(value)
        }
        if let value = arguments["statusBarStyle"] as? Int {
            self.statusBarStyle = UIStatusBarStyle.init(rawValue: value)!
        }
        if let value = arguments["txMobliNumberOffsetY"] as? NSNumber {
            self.txMobliNumberOffsetY = value
        }
        if let value = arguments["uncheckedImg"] as? [String: Any] {
            self.uncheckedImg = toUIImage(value)
        } else if let image = UIImage(innerName: "checkBox_unSelected@3x.png") {
            self.uncheckedImg = image
        }
        if let value = arguments["viewBackImg"] as? [String: Any] {
            self.viewBackImg = toUIImage(value)
        }
        if let value = arguments["webNavColor"] as? [String: Any] {
            self.webNavColor = toUIColor(value)
        }
        if let value = arguments["webNavReturnImg"] as? [String: Any] {
            self.webNavReturnImg = toUIImage(value)
        } else if let image = UIImage(innerName: "close@3x.png") {
            self.webNavReturnImg = image
        }
        if let value = arguments["webNavTitleAttrs"] as? [String: Any] {
            self.webNavTitleAttrs = toNSAttributedStringAttributes(value)
        }
    }
}
